package com.scau.ums.service.imp.listUser;

import com.scau.ums.mapper.StudentMapper;
import com.scau.ums.mapper.UserDIYMapper;
import com.scau.ums.model.Maintainer;
import com.scau.ums.model.Student;
import com.scau.ums.model.Teacher;
import com.scau.ums.service.ListUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author xfy
 * @version 1.0
 * @date 2019/8/2 13:58
 */
@Service
public class ListUserImp implements ListUserService {

    @Autowired
    UserDIYMapper userDIYMapper;

    /**
     * 根据当前页获取该页的学生列表数据
     */
    @Override
    public List<Student> getStudentCurPageRecords(int curPage, String searchKeyword) {
        int start = (curPage - 1) * pageSize;//当前开始记录下标
        return userDIYMapper.getStudentListByLimit(start,pageSize,searchKeyword);
    }
    /**
     * 根据当前页获取该页的教师列表数据
     */
    @Override
    public List<Teacher> getTeacherCurPageRecords(int curPage, String searchKeyword) {
        int start = (curPage - 1) * pageSize;//当前开始记录下标
        return userDIYMapper.getTeacherListByLimit(start,pageSize,searchKeyword);
    }

    /**
     * 根据当前页获取该页的维修员列表数据
     */
    @Override
    public List<Map<String,Object>> getMaintainerCurPageRecords(int curPage, String searchKeyword) {
        int start = (curPage - 1) * pageSize;//当前开始记录下标
        return userDIYMapper.getMaintainerListByLimit(start,pageSize,searchKeyword);
    }

    /**
     * 获取学生数据库列表总页数
     */
    @Override
    public int getStudentPageSum(String searchKeyword) {
        int totalRecord = userDIYMapper.getStudentNumber(searchKeyword);//总数据记录
        System.out.println("总记录：" + totalRecord);
        double tmp = (double)totalRecord/pageSize;
        int pageSum = (int) Math.ceil(tmp);//总页数
        System.out.println("总页数：" + pageSum);
        return pageSum;
    }

    @Override
    public int getTeacherPageSum(String searchKeyword) {
        int totalRecord = userDIYMapper.getTeacherNumber(searchKeyword);//总数据记录
        System.out.println("总记录：" + totalRecord);
        double tmp = (double)totalRecord/pageSize;
        int pageSum = (int) Math.ceil(tmp);//总页数
        System.out.println("总页数：" + pageSum);
        return pageSum;
    }

    @Override
    public int getMaintainerPageSum(String searchKeyword) {
        int totalRecord = userDIYMapper.getMaintainerNumber(searchKeyword);//总数据记录
        System.out.println("总记录：" + totalRecord);
        double tmp = (double)totalRecord/pageSize;
        int pageSum = (int) Math.ceil(tmp);//总页数
        System.out.println("总页数：" + pageSum);
        return pageSum;
    }
}
